package com.zlp.controller;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.zlp.common.api.Result;
import com.zlp.dto.resource.*;
import com.zlp.enums.resource.ComponentDetailEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Classname ResourceController
 * @Description 资源位管理
 * @Date 2022/11/28 16:27
 * @Created by ZouLiPing
 */
@Slf4j(topic = "ResourceController")
@RestController
@RequestMapping("resource")
@Api(value = "resource", tags = "资源位管理")
public class ResourceController {

    /**
     * cf7d79d1c9053c6db7acaa60b71da5af4565214669f1bd43e36a981b3bf615af
     * 获取资源位信息
     * @author ZouLiPing
     * @date 2022/11/29 10:36
     */
    @ApiOperation( "获取资源位信息")
    @PostMapping(value = "getResource")
    public Result<ResourceResp> getResource(@Valid @RequestBody ResourceReq resourceReq){

        log.info("getResource req resourceReq={}",JSON.toJSONString(resourceReq));
        ResourceResp resourceResp = new ResourceResp();
        resourceResp.setFrontCategoryId(resourceReq.getFrontCategoryId());
        List<ResourceDetailResp> resourceDetailRespList =  Lists.newArrayList();

        // 	1001:图片-Banner位;
        ResourceDetailResp banner = new ResourceDetailResp();
        banner.setComponentResp(ComponentResp.convertComponent(ComponentDetailEnum.COMPONENT_1001));
        banner.setIsShowData(1);
        banner.setConfigData(JSON.toJSONString(new BannerResp()));
        resourceDetailRespList.add(banner);

        //	2001:标题-标题文本;
        ResourceDetailResp titleText = new ResourceDetailResp();
        titleText.setComponentResp(ComponentResp.convertComponent(ComponentDetailEnum.COMPONENT_2001));
        titleText.setIsShowData(1);
        titleText.setConfigData(JSON.toJSONString(TitleResp.getTitleResp()));
        resourceDetailRespList.add(titleText);

        //	3001:魔方-活动魔方-1排2个;
        ResourceDetailResp cubeTwoinRowOne = new ResourceDetailResp();
        cubeTwoinRowOne.setComponentResp(ComponentResp.convertComponent(ComponentDetailEnum.COMPONENT_3001));
        cubeTwoinRowOne.setIsShowData(1);
        cubeTwoinRowOne.setConfigData(JSON.toJSONString(new MagicCubeResp()));
        resourceDetailRespList.add(cubeTwoinRowOne);


        //	4001:商品-商品图+商品信息;
        ResourceDetailResp productInfo = new ResourceDetailResp();
        productInfo.setComponentResp(ComponentResp.convertComponent(ComponentDetailEnum.COMPONENT_4001));
        productInfo.setConfigData(JSON.toJSONString(new ProductResp()));
        productInfo.setIsShowData(1);
        resourceDetailRespList.add(productInfo);

        //	3006:魔方-商品长图;
        ResourceDetailResp commodityLongChart = new ResourceDetailResp();
        commodityLongChart.setComponentResp(ComponentResp.convertComponent(ComponentDetailEnum.COMPONENT_3006));
        commodityLongChart.setIsShowData(0);
        commodityLongChart.setConfigData(null);
        resourceDetailRespList.add(commodityLongChart);

        resourceResp.setResourceDetailRespList(resourceDetailRespList);
        log.info("getResource resp resourceResp={}",JSON.toJSONString(resourceResp));
        return Result.success(resourceResp);
    }


}
